package com.tz.hospital.controller.pres;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tz.hospital.entity.hospital_drug;
import com.tz.hospital.entity.hospital_emp;
import com.tz.hospital.entity.hospital_project;
import com.tz.hospital.entity.hospital_xmjl;
import com.tz.hospital.entity.hospital_ypcf;
import com.tz.hospital.service.presService;
import com.tz.hospital.service.registerService;
import com.tz.hospital.service.impl.presServiceImpl;
import com.tz.hospital.service.impl.registerServiceImpl;

/**
 * Servlet implementation class kcfController
 */
@WebServlet("/kcfController")
public class kcfController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public kcfController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		registerService rs = new registerServiceImpl();
		presService ps=new presServiceImpl();
		int ghid=Integer.valueOf((String) request.getParameter("ghid"));
		int brid=Integer.valueOf((String) request.getParameter("brid"));
		HttpSession session= request.getSession();
		session.setAttribute("ghid", ghid);
		session.setAttribute("brid", brid);
		System.out.println(ghid+"****"+brid);
		List<hospital_emp> lb=rs.tjemp(brid);
		List<hospital_ypcf> lyj=ps.seecfyp(ghid);
		List<hospital_xmjl> lxj=ps.seecfxm(ghid);
		List<hospital_drug> lyp=ps.allyp();
		List<hospital_project> lxm=ps.allxm();
		System.out.println(lyp.toString());
		if(!lyj.isEmpty()) {
			
			request.setAttribute("lb", lb);
			request.setAttribute("lyj", lyj);
			request.setAttribute("lxj", lxj);
			request.setAttribute("cfid", ghid);
			request.setAttribute("lyp", lyp);
			request.setAttribute("lxm", lxm);
			request.getRequestDispatcher("/JSP/kcf.jsp").forward(request, response);
		}else {
			System.out.println("no");
			request.setAttribute("lb", lb);
			request.setAttribute("lyp", lyp);
			request.setAttribute("cfid", ghid);
			request.setAttribute("lxm", lxm);
			request.getRequestDispatcher("/JSP/kcf.jsp").forward(request, response);
		}
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
